/* 轮播图 */
var swiper = new Swiper(".mySwiper", {
	slidesPerView: 1,
	spaceBetween: 30,
	loop: true,
	autoplay: {
		disableOnInteraction: false,
		delay: 3000,
	},
	pagination: {
		el: ".swiper-pagination",
		clickable: true,
	},
	navigation: {
		nextEl: ".swiper-button-next",
		prevEl: ".swiper-button-prev",
	},
});

/* api  js效果 */
/* 采用时间委派的方式注册事件 */
let li = document.querySelector("#li");
let filename = ""; //保存图片的名字

li.addEventListener('mouseover', function (e) {
	//定义变量保存事件源li
	let t = e.target;
  
	//如果事件源父节点是li, 就把事件源的父节点赋值给t
	if (t.parentNode.nodeName === 'LI') t = t.parentNode
	if (t.nodeName === 'LI') {
	  t.style.backgroundColor = 'rgb(47,126,233)'
	  t.style.color = '#fff'
	  let path = t.children[0].src; //定义变量保存文件的路径
	  let i1 = path.lastIndexOf('/');
	  let i2 = path.lastIndexOf('.');
	  filename = path.slice(i1+1, i2) //截取文件名
	  t.children[0].src = `../../assets/imgs/${filename}-c.svg`
	}
  })
  

/* 移入移出 效果*/
  li.addEventListener('mouseout', function (e) {
	//定义变量保存事件源li
	let t = e.target;
	//如果事件源父节点是li, 就把事件源的父节点赋值给t
	if (t.parentNode.nodeName === 'LI') t = t.parentNode
  
	if (t.nodeName === 'LI') {
	  t.style.backgroundColor = '#fff';
	  t.style.color = '#000'
	  t.children[0].src = `../../assets/imgs/${filename}.svg`
	}
  })


  /* 独角兽自动轮播效果 */
let height=document.querySelectorAll('.height')
let mabanner=document.querySelector('.ma-banner')
/* 定义变量保存索引 */   /* 这里的值是会变化的 */
let index=0;

let time=setInterval(function(){
	//对激活样式的类名进行删除 这里index是0
	height[index%height.length].classList.remove('jh')
	//索引自增
	index++;
	//这是下一个界面
	height[index%height.length].classList.add('jh')
},2000)

mabanner.addEventListener('mouseover',function(){
	clearInterval(time)
})

mabanner.addEventListener('mouseout',function(){
	time=setInterval(function(){
		
		height[index%height.length].classList.remove('jh')
		
		index++;
		//
		height[index%height.length].classList.add('jh')
	},2000)
})


/* 返回顶部 */
let scool=document.querySelector('.scolltop')

scool.addEventListener('click',function(){

	window.scrollTo({

		top:0,
		behavior:"smooth"

	})

})
